<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Origami::Encryption::EncryptedString</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Origami::Encryption::EncryptedString</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/origami/encryption_rb.html">
                origami/encryption.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Module for encrypted <a href="../String.html">String</a>.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000263">decrypt!</a>&nbsp;&nbsp;
      <a href="#M000262">encrypt!</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="EncryptedObject.html">EncryptedObject</a></span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000263" class="method-detail">
        <a name="M000263"></a>

        <div class="method-heading">
          <a href="#M000263" class="method-signature">
          <span class="method-name">decrypt!</span><span class="method-args">(derive_key = true)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000263-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000263-source">
<pre>
     <span class="ruby-comment cmt"># File origami/encryption.rb, line 400</span>
400:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrypt!</span>(<span class="ruby-identifier">derive_key</span> = <span class="ruby-keyword kw">true</span>)
401:         <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@decrypted</span>
402:           <span class="ruby-identifier">key</span> = <span class="ruby-identifier">derive_key</span> <span class="ruby-value">? </span><span class="ruby-identifier">compute_object_key</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@encryption_key</span>
403:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-ivar">@algorithm</span>.<span class="ruby-identifier">decrypt</span>(<span class="ruby-identifier">key</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_str</span>))
404:           <span class="ruby-ivar">@decrypted</span> = <span class="ruby-keyword kw">true</span>
405:         <span class="ruby-keyword kw">end</span>
406: 
407:         <span class="ruby-keyword kw">self</span>
408:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000262" class="method-detail">
        <a name="M000262"></a>

        <div class="method-heading">
          <a href="#M000262" class="method-signature">
          <span class="method-name">encrypt!</span><span class="method-args">(derive_key = true)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000262-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000262-source">
<pre>
     <span class="ruby-comment cmt"># File origami/encryption.rb, line 379</span>
379:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encrypt!</span>(<span class="ruby-identifier">derive_key</span> = <span class="ruby-keyword kw">true</span>)
380:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@decrypted</span>
381:           <span class="ruby-identifier">key</span> = <span class="ruby-identifier">derive_key</span> <span class="ruby-value">? </span><span class="ruby-identifier">compute_object_key</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@encryption_key</span>
382:           
383:           <span class="ruby-identifier">encrypted_data</span> = 
384:           <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@algorithm</span> <span class="ruby-operator">==</span> <span class="ruby-constant">ARC4</span> <span class="ruby-keyword kw">or</span> <span class="ruby-ivar">@algorithm</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Identity</span>
385:             <span class="ruby-ivar">@algorithm</span>.<span class="ruby-identifier">encrypt</span>(<span class="ruby-identifier">key</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">value</span>)
386:           <span class="ruby-keyword kw">else</span>
387:             <span class="ruby-identifier">iv</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">16</span>) { <span class="ruby-identifier">rand</span>(<span class="ruby-value">255</span>) }.<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'C*'</span>)
388:             <span class="ruby-ivar">@algorithm</span>.<span class="ruby-identifier">encrypt</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">value</span>)
389:           <span class="ruby-keyword kw">end</span>
390: 
391:           <span class="ruby-ivar">@decrypted</span> = <span class="ruby-keyword kw">false</span>
392: 
393:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-identifier">encrypted_data</span>)
394:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">freeze</span>
395:         <span class="ruby-keyword kw">end</span>
396:         
397:         <span class="ruby-keyword kw">self</span>
398:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>